#include "FireGestureBehaviour.h"


FireGestureBehaviour::FireGestureBehaviour( ) :
	m_pTouches(0) ,
	m_tStartTouchPosition(CCPointZero),
	m_fTouchDistance(0),
	m_fMinTouchDistance(60),
	m_fMaxTouchDuration(300)
{

}


FireGestureBehaviour::~FireGestureBehaviour( )
{
	if( m_pTouches ){
		m_pTouches->removeAllObjects( );
		m_pTouches->release();
	}
}


bool FireGestureBehaviour::init( )
{
	if( !LBehaviour::init( ) )
		return false;


	m_pTouches = new CCArray( );
	this->unscheduleUpdate( );

	return true;
}


void FireGestureBehaviour::update(float dt )
{

}




bool FireGestureBehaviour::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
{

	if( m_pTouches->count() == 0 && !m_pTouches->containsObject(pTouch) )
	{
		m_pTouches->addObject( pTouch );
	}


	return true;
}


void FireGestureBehaviour::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent)
{
	if( m_pTouches->count() == 1 && m_pTouches->containsObject(pTouch) )
	{
		CCPoint startPos = pTouch->getStartLocation();
		CCPoint endPos = pTouch->getLocation( );

		float distane = ccpDistance( endPos , startPos );

		if( distane >= m_fMinTouchDistance && 0 <= m_fMaxTouchDuration )
		{
			m_tFireDirection = ccpSub( endPos , startPos );
			//Fire ?
		}
	}
}


void FireGestureBehaviour::ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent)
{

}